﻿module Sustainalytics.Screening {
    export class EnumValues {
        static getNamesAndValues(e: any) {
            return this.getNames(e).map(name => ({ label: name, id: e[name] as number }));
        }

        static getNames(e: any) {
            return this.getObjectValues(e).filter(v => typeof v === "string") as string[];
        }

        static getValues(e: any) {
            return this.getObjectValues(e).filter(v => typeof v === "number") as number[];
        }

        private static getObjectValues(e: any): (number | string)[] {
            return Object.keys(e).map(k => e[k]);
        }

        static flagsToList(e: any, flags: number)
        {
            var flagsArray = [];
            for (var i = 0; i < EnumValues.getNamesAndValues(e).length; i++) {
                var mask = 1 << i;
                var flag = mask & flags;
                if (flag != 0)
                    flagsArray.push(flag);
            }
            return flagsArray;
        }
    }

    export enum CompanyTypeEnum {        
        Public = 1,
        Private = 2,        
        Comprehensive = 4,
        Core = 8       
    }
    
    export let CompanyTypeOptions = EnumValues.getNamesAndValues(CompanyTypeEnum);
} 